using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

namespace Instedd.Labs.Geoblogging.Website
{
    public partial class PostFeed : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String feedFileForSmsKml = ConfigurationManager.AppSettings["FeedFileForSmsKml"].ToString();
            String feedFileForSmsGeoRss = ConfigurationManager.AppSettings["FeedFileForSmsGeoRss"].ToString();
            String filenameToUse = null;

            String feedType = Request.QueryString["t"].ToString();
            if (feedType.ToLower() == "georss")
            {
                filenameToUse = feedFileForSmsGeoRss;
            }
            else if(feedType.ToLower() == "kml")
            {
                filenameToUse = feedFileForSmsKml;
            }
            else
            {
                // not a known feed type, error out
                Response.StatusCode = 500;
                Response.StatusDescription = "Invalid feed type (only 'georss' and 'kml' are allowed)";
                return;
            }

            string content = this.Request.ContentEncoding.GetString(this.Request.BinaryRead(this.Request.ContentLength));

            using (StreamWriter sw = File.CreateText(filenameToUse))
            {
                sw.Write(content);
            }


        }
    }
}
